<template>
	<view style=" background-image: url('../../static/beijing.jpg');background-repeat:no-repeat;
   background-size:100% 100%;
   -moz-background-size:100% 100%;width: 750upx;height: 1600upx;">
		<div style="height: 500upx;padding-top: 200upx;padding-left: 250upx;padding-right: 250upx;">
            <image style="border-radius: 1000upx;width: 250upx;height: 250upx;" :src="picture"></image>
        </div>
        <div style="display: flex;flex-direction: column;margin-top: 60upx;padding-left: 100upx;padding-right: 100upx;">
           <input  v-model="account" type="number" placeholder="账号" style="border-radius: 50upx;width: 550upx;height: 100upx;padding-left: 50upx;padding-top: 20upx;padding-bottom: 20upx;background-color: #FEFEFE;" placeholder-style="color:#999999;font-size:35upx" confirm-type="next" @blur="touxiang" >
           <input v-model="password" type="text" placeholder="密码" style="border-radius: 50upx;width: 550upx;height: 100upx;padding-left: 50upx;padding-top: 20upx;padding-bottom: 20upx;background-color: #FEFEFE;margin-top: 50upx;" placeholder-style="color:#999999;font-size:35upx" password="true" confirm-type="done">
           <div style="margin-bottom: 20upx;justify-content: flex-end;margin-top: 20upx;display: flex;">
               <text style="color: #00a1e9;font-size: 26upx;width: 120upx;">忘记密码</text>
           </div>
           
           <button style="margin-top: 40upx;background-color: #fe9f1a;height: 100upx;padding-bottom: 30upx;padding-left: 200upx;padding-right: 200upx;border-radius: 80upx;opacity:0.7;width: 550upx;"  @click.stop="logins">
               <text style="color: #FFFFFF;font-size: 34upx;font-weight: 800;opacity: 1;letter-spacing:15upx">登录</text>
           </button>
           <div style="margin-top: 50upx;width: 550upx;text-align: center;"><text style="color: #fda830;font-size: 34upx;letter-spacing:15upx" @click.stop="register">注册</text></div>
        </div>
	</view>
</template>

<script>
    import{
        mapState,
        mapMutations
    }from 'vuex'
	export default {
        computed:mapState(['forcedLogin','hasLogin','userName']),
		data() {
			return {
				account:'',
                password:'',
                picture:'../../static/touxiang.png'
			}
		},
		methods: {
			...mapMutations(['login']),
            toMain(user){
               this.login(user); 
               uni.switchTab({
                   url: '../index/index'
               });   
               // console.log(this.forcedLogin);
               // uni.navigateBack();
               
               // if(this.forcedLogin){
               //     uni.reLaunch({
               //         url:'../index/index'
               //     })
               // }else{
                   
               // }
            },
            register(){
                uni.navigateTo({
                    url:"../resgiter/resgiter"
                })
            },
            logins(){
             let {account,password} = this;
              console.log(account);
              console.log(password);
              
              if(account == ""){
                  uni.showToast({
                      title: '请输入账号',
                      duration: 3000,
                      icon:"none"
                  }); 
                   return;
              }
              
              if(password == ""){
                 uni.showToast({
                     title: '请输入密码',
                     duration: 3000,
                     icon:"none"
                 }); 
                  return; 
              }
              
              
                
              let c = this;
             uni.request({
                  url: 'https://07cr7.live:8996/login',
                  method: 'POST',
                  data: {account,password},
                  header:{
                  	'Content-Type':'application/x-www-form-urlencoded'
                  },
                  sslVerify:false,
                  success: (res) => {
                      
                      console.log(res)
                      
                      if(res.statusCode == 200){
                          
                          if(res.data.statue == 0){
                          
                          c.toMain(res.data);
                      }
                      if(res.data.statue == 1){
                          
                         uni.showToast({
                             title: '认证失败',
                             duration: 1500,
                             icon:"none"
                         });  
                      }
                          }
                      
                      if(res.statusCode == 401){
                        uni.showToast({
                            title: '账号或者密码错误,请重新输入',
                            duration: 3000,
                            icon:"none"
                        });  
                      }
                    if(res.statusCode == 500){
                      uni.showToast({
                          title: '请求出错',
                          duration: 3000,
                          icon:"none"
                      });  
                    }  
                      
                  }
              });
            
            },
            touxiang(){
                let c = this;
                 let {account,password} = this;
                  console.log(account);
                 uni.request({
                     url:"https://07cr7.live:8996/getHeadPortrait",
                     data:{
                         account
                     },
                     sslVerify:false,
                     method:'GET',
                     success(res) {
                       console.log(res)
                       if(res.data.statue == 0){
                          
                                   c.picture = res.data.HeadPortrait
                                   
                                   uni.setStorage({
                                       key:'touxiang',
                                       data:res.data.HeadPortrait
                                   })
                                   
                               }
                               
                               if(res.statusCode == 500){
                                 uni.showToast({
                                     title: '请求出错',
                                     duration: 3000,
                                     icon:"none"
                                 });  
                               }   
                     }
                 })
                
            }
		},
        onLoad() {
       console.log(this.hasLogin);
            if(this.hasLogin){
                var c = this;
              uni.switchTab({
                  url: '../index/index'
              })
              }  
                // uni.showModal({
                //     title:'未登录',
                //     content:'您未登录，需要登录后才能继续',
                //     success(res) {
                //         if(res.confirm){
                            
                //             uni.navigateTo({
                //                 url:'../login/login'
                //             })
                            
                //             // if(c.forcedLogin){
                //             //     uni.reLaunch({
                //             //         url:'../login/login'
                //             //     })
                //             // }else{
                //             //     uni.navigateTo({
                //             //         url:'../login/login'
                //             //     })
                //             // }
                            
                            
                            
                //         }
                //     }
                // })
            
        
	
    }
    }
</script>

<style>
page{
  
}
</style>
